﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Tool
{
	public static class InterfaceAPI
	{
		[DllImport("kernel32")]
		public static extern long GetTickCount();
		[DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "GetPrivateProfileStringA")]
		public static extern int GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

		/// <summary>
		/// 将指定的键和值写到指定的节点，如果已经存在则替换
		/// </summary>
		/// <param name="lpAppName">节点名称</param>
		/// <param name="lpKeyName">键名称。如果为null，则删除指定的节点及其所有的项目</param>
		/// <param name="lpString">值内容。如果为null，则删除指定节点中指定的键。</param>
		/// <param name="lpFileName">INI文件</param>
		/// <returns>操作是否成功</returns>
		[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);


		[DllImport("user32", CharSet = CharSet.Ansi, EntryPoint = "FindWindowA")]
		public static extern int FindWindow(ref string lpClassName, ref string lpWindowName);
		[DllImport("user32")]
		public static extern int BringWindowToTop(int hwnd);
		[DllImport("user32")]
		public static extern int CloseWindow(int hwnd);
		[DllImport("user32")]
		public static extern int DestroyWindow(int hwnd);
		[DllImport("user32")]
		public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int wFlags);
		[DllImport("user32")]
		public static extern int MessageBeep(int wType);
		[DllImport("kernel32")]
		public static extern int Beep(int dwFreq, int dwDuration);
		[DllImport("user32", CharSet = CharSet.Ansi, EntryPoint = "SendMessageA")]
		public static extern int SendMessage(int hwnd, int wMsg, int wParam, object lParam);
		[DllImport("shell32.dll", CharSet = CharSet.Ansi, EntryPoint = "ShellExecuteA")]
		public static extern int ShellExecute(int hwnd, ref string lpOperation, ref string lpFile, ref string lpParameters, ref string lpDirectory, int nShowCmd);
		[DllImport("kernel32")]
		public static extern void Sleep(long dwMilliseconds);
	}
}
